package cc.telecomdigital.tdstock;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

/**
 * Customer Dialog alert message
 * 
 * @author ouyangzhihui
 */
public class CustomizeDialogDualMax extends Dialog implements OnClickListener
{
	/** When a button is pressed **/
	public interface IOnDialogButtonClick
	{
		public void OnResponse();		
	}
	
	/** When Dialog is onCancel **/
	public interface IOnDialogCancel
	{
		public void OnResponse();		
	}	
	
	private IOnDialogButtonClick button1Handler = null;
	private IOnDialogButtonClick button2Handler = null;	
	private IOnDialogCancel      cancelHandler  = null;
	
	/** Especially design to display content in HTML view, replacing character to Web style **/
	public CustomizeDialogDualMax(Context context)
	{
		super(context, R.style.dialog);
		setContentView(R.layout.richdialog_dual);

		findViewById(R.id.richdialog_dual_Button1).setOnClickListener(this);
		findViewById(R.id.richdialog_dual_Button2).setOnClickListener(this);
		//Set when the window will be cancel
		setOnCancelListener(new OnCancelListener()
		{
			@Override
			public void onCancel(DialogInterface dialog)
			{
				if (cancelHandler == null)
					return;

				cancelHandler.OnResponse();
			}
		});		
	}

	public void SetSingleButton(String iText, IOnDialogButtonClick iResponder)
	{
		((TextView)findViewById(R.id.richdialog_dual_Button1)).setText(iText);
		button1Handler = iResponder;
		
		findViewById(R.id.richdialog_dual_Button2).setVisibility(View.GONE);
	}

	public void SetDualButton(String iText1, IOnDialogButtonClick iResponder1, 
						 String iText2, IOnDialogButtonClick iResponder2)
	{
		((TextView)findViewById(R.id.richdialog_dual_Button1)).setText(iText1);
		button1Handler = iResponder1;

		findViewById(R.id.richdialog_dual_Button2).setVisibility(View.VISIBLE);		
		((TextView)findViewById(R.id.richdialog_dual_Button2)).setText(iText2);
		button2Handler = iResponder2;		
	}	
	
	public void SetOnCancelFeature(boolean iEnable, IOnDialogCancel iRespHandler)
	{
		setCancelable(iEnable);
		cancelHandler = iRespHandler;
	}
		
	public void SetTextContent(String iHeader, String iContent)
	{
		SetHeader(iHeader);
		SetMsgContent(iContent);
	}
	
	public void SetHeader(String iText)
	{
		((TextView)findViewById(R.id.richdialog_dual_Caption)).setText(iText);
	}

	public void SetMsgContent(String iMsg)
	{
		((TextView)findViewById(R.id.richdialog_dual_Content)).setText(iMsg);
	}

	@Override
	public void onClick(View iViewObj)
	{
		int objId;
		
		objId = iViewObj.getId();
		switch(objId)
		{
			case R.id.richdialog_dual_Button1:
				dismiss();
				if (button1Handler != null)
					button1Handler.OnResponse();
				break;

			case R.id.richdialog_dual_Button2:
				dismiss();
				if (button2Handler != null)
					button2Handler.OnResponse();
				break;
				
		}
	}
}
